<?php
namespace Admin\Controller;
use Admin\Controller\CommonController;
class ZhanshiController extends CommonController {

	public function index() {

		$M=new \Think\Model("zhanshi");
		$count = $M->count();
  
		$Page =new \Think\Page($count,10);
		$Page -> setConfig('first','首页');
		$Page -> setConfig('last','末页');
		$Page -> setConfig('prev','上一页');
		$Page -> setConfig('next','下一页');
		$Page -> setConfig('theme',' <div style="margin-top:2px">  %FIRST%  %UP_PAGE%    %LINK_PAGE%  %DOWN_PAGE%   %END% </div> ');



		$show = $Page->show();

	
        $list=M('zhanshi')->order("id desc")->limit($Page->firstRow, $Page->listRows)->select();
        // $strsql = "select a.id,a.name,a.fengge,a.huxing,a.area,a.price,a.intro,a.img,a.userid,b.user as username ";
        // $strsql .="from zyb_zhanshi a,zyb_user  b where a.userid = b.id and a.userid = $userid order by a.id desc ";

		foreach ($list as  &$value) {
			if (strlen($value['name']>15)) {
			$value['name']=mb_substr(strip_tags(htmlspecialchars_decode($value['intro'])),0,15,'utf-8').'...';

			}
         if(strlen($value['intro'])>30){
            $value['intro']=mb_substr(strip_tags(htmlspecialchars_decode($value['intro'])),0,30,'utf-8').'...';
         }else{$value['intro']=htmlspecialchars_decode($value['intro']);}

       
        // $type = M('zlist')->where(array('id'=>$value['type']))->find();

        // $list[$key]['type'] =$type['type_name'];
        
        }


		$this->assign("list", $list);

		$this->assign("page",$show);

		$this->display();
	}
	
	
	/**
	 +----------------------------------------------------------
	 * 父栏目
	 +----------------------------------------------------------
	 */
	 public function lider(){

	 	$lider = M('zlist');
	 	$list = $lider->select();
	 	$this->assign('list',$list);


	 	$this->display();
	 }

     public function huxing(){

	 	$huxing = M('huxing');
	 	$list = $huxing->select();
	 	$this->assign('huxing',$list);


	 	$this->display();
	 }


	 public function delete(){
	 	$id = I('get.id');
	 	if ($id>0) {
	 		M('zlist')->where(array('id'=>$id))->delete();
                   
	 		//M('zixun')->where(array('type'=>$id))->delete();

	 		$this->success('删除成功',U('Zhanshi/lider'));
	 		exit();
	 		# code...
	 	}


	 }

	 public function huxingdel(){
	 	$id = I('get.id');
	 	if ($id>0) {
	 		M('huxing')->where(array('id'=>$id))->delete();
                   
	 		//M('zixun')->where(array('type'=>$id))->delete();

	 		$this->success('删除成功',U('Zhanshi/huxing'));
	 		exit();
	 		# code...
	 	}


	 }



		
	/**
	 +----------------------------------------------------------
	 * 添加管理员
	 +----------------------------------------------------------
	 */
    Public function addlist(){
    	if(IS_POST){
                    

    		$data=array();
    		$data=I('post.');
    		if(M('zlist')->add($data)){
 				$this->success('分类添加成功',U('Zhanshi/index'));
 				exit();
    		}else{
    			$this->success('分类添加失败',U('Zhanshi/index'));
    			exit();
    		}



    	}




    	$this->display();
    }





    Public function addhuxing(){
    	if(IS_POST){
                    

    		$data=array();
    		$data=I('post.');



    		if(M('huxing')->add($data)){
 				$this->success('分类添加成功',U('Zhanshi/index'));
 				exit();
    		}else{
    			$this->success('分类添加失败',U('Zhanshi/index'));
    			exit();
    		}



    	}




    	$this->display();
    }



		
	/**
	 +----------------------------------------------------------
	 * 添加管理员
	 +----------------------------------------------------------
	 */



public function addAdmin() {
		$lis=M('zlist');
		$list=$lis->select();
		$ljj=M('huxing')->select();
		$this->assign('ljj',$ljj);
		$this->assign('list',$list);
		if (IS_POST) {
			$data=array();
			$data=I('post.');

        
                $upload = new \Think\Upload();// 实例化上传类
                $upload->maxSize   =     553145728 ;// 设置附件上传大小
                $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
                $upload->rootPath  =     './Uploads/'; // 设置附件上传根目录
                $upload->savePath  =     ''; // 设置附件上传（子）目录
                // 上传文件
                $info   =   $upload->upload();
                if(!$info) {// 上传错误提示错误信息
                    $this->error($upload->getError());
                }else{// 上传成功
                    $data["img"]=$info["pic"]["savepath"].$info["pic"]["savename"];
                  
                }



			$data['intro']=stripslashes(I('post.intro'));

			if(M('zhanshi')->add($data)){
				$this->success('添加成功',U('Zhanshi/index'));
			}else{
				$this->error(M('zhanshi')->getError());
			}
		} else {
		
			$this->display();
		}
	}
	

   





	/**
	 +----------------------------------------------------------
	 * 修改密码
	 +----------------------------------------------------------
	 */
		public function edit() {

	        $id=I('get.id');
		    $zi=M('zhanshi');
		    $map['id']=$id;

		    $info=$zi->where($map)->find();
		  
		    $info['intro'] =html_entity_decode($info['intro']);

		    $this->assign('info',$info);
	
			$ljj=M('huxing')->select();
		$this->assign('ljj',$ljj);
	
          $zlist=M('zlist');
          $list=$zlist->select();
          $this->assign("list",$list);

      
		if (IS_POST) {

			$upload = new \Think\Upload();// 实例化上传类
                $upload->maxSize   =     553145728 ;// 设置附件上传大小
                $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
                $upload->rootPath  =     './Uploads/'; // 设置附件上传根目录
                $upload->savePath  =     ''; // 设置附件上传（子）目录
                // 上传文件
                $info   =   $upload->upload();
                if(!$info) {// 上传错误提示错误信息
                   unset($data["img"]);
                }else{// 上传成功
                    $data["img"]=$info["pic"]["savepath"].$info["pic"]["savename"];
                  
                }


           
			  $ff=I('post.id');
			  	$data['area']=I('post.area');
			  		$data['price']=I('post.price');
			  	$data['fengge']=I('post.fengge');
			$data['huxing']=I('post.huxing');
		    $data['name']=I('post.name');

     
           $data['intro']=stripslashes(I('post.intro'));
   
	   
			if(M('zhanshi')->where("id=".$ff)->save($data)){
				$this->success('修改成功',U('Zhanshi/index'));
			}else{
				$this->success('修改成功',U('Zhanshi/index'));
			}
		} else {
		
			$this->display();
		}
	}
	
	
	/**
	 +----------------------------------------------------------
	 * 修改 管理员
	 +----------------------------------------------------------
	 */



	public function del(){

		$ids = $_POST['id'];


      
		$str="('".implode("','",$ids)."')";
	
      

	
		if (M("zhanshi")->where("id in ".$str)->delete()) {
			
			$this->success('删除成功');
		} else {
			$this->success('删除失败');
		}
	}

public function fenlei() {

	        $id=I('get.id');
		    $zi=M('zlist');
		    $map['id']=$id;

		    $info=$zi->where($map)->find();
		  
		


		    $this->assign('info',$info);
	
  
      
		if (IS_POST) {
           
			$data=I('post.');

            $id=I('get.id');

			if(M('zlist')->where("id=".$data['dd'])->save($data)){
				$this->success('修改成功',U('Zhanshi/lider'));
			}else{
				$this->success('修改失败',U('Zhanshi/lider'));
			}
		} else {
		
			$this->display();

		}
	}
	









    		
}

    
  


?>